from tkinter import *
import time
import math
from mymodule.game_02_base import GameBase
from mymodule.game_02_base import Environment
from mymodule.game_02_base import Ball
from mymodule.game_02_base import Border
    
class BallGame(GameBase):
    def __init__(self):
        super().__init__()
        
    def run(self):
        border = Border(100,700,100,500)
        self.make_wall(border.left,border.top,border.right-border.left,border.bottom-border.top)
        
        ball = self.make_ball(Environment.BALL_X,Environment.BALL_Y,Environment.BALL_RADIUS,Environment.BALL_VELOCITY_X,Environment.BALL_VELOCITY_Y,'red')
        
        while True:
            self.move_ball(ball)
            if(ball.x+ball.velocity_x<=border.left):
                ball.velocity_x = abs( ball.velocity_x)
                
            if(ball.x+ball.velocity_x>=border.right):
                ball.velocity_x = - abs( ball.velocity_x)
            if(ball.y+ball.velocity_y<=border.top):
                ball.velocity_y = abs( ball.velocity_y)

            if(ball.y+ball.velocity_y>=border.bottom):  
                ball.velocity_y = - abs( ball.velocity_y)
                
            self.redraw_ball(ball)
            self.tk.update()
            time.sleep(Environment.DURATION)
            
game = BallGame()
game.run()